package SingletonPattern;

public class TVRemoteControl {
    // 私有静态实例
    private static TVRemoteControl instance;

    // 私有构造方法，防止外部实例化
    private TVRemoteControl() {}

    // 提供一个全局访问点
    public static TVRemoteControl getInstance() {
        if (instance == null) {
            instance = new TVRemoteControl();
        }
        return instance;
    }

    // 示例方法
    public void turnOn() {
        System.out.println("TV is turned on.");
    }

    public static void main(String[] args) {
        TVRemoteControl remote1 = TVRemoteControl.getInstance();
        TVRemoteControl remote2 = TVRemoteControl.getInstance();

        // 两者应该是同一个实例
        System.out.println(remote1 == remote2); // 输出 true
        remote1.turnOn();
    }
}